/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: Factor2Evaluate.java
 * Date: 17/11/2010
 */

package com.ingenius.sau.shared.model.core;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.FetchGroup;
import javax.jdo.annotations.FetchGroups;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NullValue;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * Class <strong>Factor2Evaluate</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@FetchGroups({
		@FetchGroup(name = "with_process", members = { @Persistent(name = "process") }),
		@FetchGroup(name = "with_features", members = { @Persistent(name = "features2Evaluate") }) })
public class Factor2Evaluate implements BaseBean {

	// DATA

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;

	@Persistent(nullValue = NullValue.NONE)
	private String name;

	@Persistent(nullValue = NullValue.NONE)
	private String description;

	@Persistent(nullValue = NullValue.NONE)
	private float weighing;

	@Persistent(nullValue = NullValue.NONE)
	private String justify;

	@Persistent
	private float grade;

	@Persistent
	private SelfEvaluation process;

	@Persistent(mappedBy = "factor2Evaluate")
	@Element(dependent = "true")
	private List<Feature2Evaluate> features2Evaluate;

	// CONSTRUCTORS

	public Factor2Evaluate() {
	}

	public Factor2Evaluate(String id) {
		this.id = id;
	}

	// METHODS
	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public float getWeighing() {
		return weighing;
	}

	public void setWeighing(float weighing) {
		this.weighing = weighing;
	}

	public String getJustify() {
		return justify;
	}

	public void setJustify(String justify) {
		this.justify = justify;
	}

	public float getGrade() {
		return grade;
	}

	public void setGrade(float grade) {
		this.grade = grade;
	}

	public SelfEvaluation getProcess() {
		return process;
	}

	public void setProcess(SelfEvaluation process) {
		this.process = process;
	}

	public List<Feature2Evaluate> getFeatures2Evaluate() {
		return (features2Evaluate == null) ? features2Evaluate = new ArrayList<Feature2Evaluate>()
				: features2Evaluate;
	}

	public void setFeatures2Evaluate(List<Feature2Evaluate> features2Evaluate) {
		this.features2Evaluate = features2Evaluate;
	}

	public void addFeature2Evaluate(Feature2Evaluate feature2Evaluate) {
		getFeatures2Evaluate().add(feature2Evaluate);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Factor2Evaluate) {
			return ((Factor2Evaluate) obj).getId().equals(id);
		}
		return false;
	}

	public Factor2Evaluate toDTO() {
		if (this != null) {
			this.setFeatures2Evaluate(null);
		}
		return this;
	}

}
